package com.ruoyi.system.controller;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Hospital;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.HospitalIntro;
import com.ruoyi.system.service.IHospitalIntroService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 医院介绍Controller
 *
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/intor")
public class HospitalIntroController extends BaseController {
    @Autowired
    private IHospitalIntroService hospitalIntroService;

    /**
     * 查询医院介绍列表
     */
    @RequiresPermissions("system:intor:list")
    @GetMapping("/list")
    public TableDataInfo list(HospitalIntro hospitalIntro) {
        startPage();
        List<HospitalIntro> list = hospitalIntroService.selectHospitalIntroList(hospitalIntro);
        return getDataTable(list);
    }

    /**
     * 导出医院介绍列表
     */
    @RequiresPermissions("system:intor:export")
    @Log(title = "医院介绍", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HospitalIntro hospitalIntro) {
        List<HospitalIntro> list = hospitalIntroService.selectHospitalIntroList(hospitalIntro);
        ExcelUtil<HospitalIntro> util = new ExcelUtil<HospitalIntro>(HospitalIntro.class);
        util.exportExcel(response, list, "医院介绍数据");
    }

    /**
     * 获取医院介绍详细信息
     */
    @RequiresPermissions("system:intor:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(hospitalIntroService.selectHospitalIntroById(id));
    }

    /**
     * 新增医院介绍
     */
    @RequiresPermissions("system:intor:add")
    @Log(title = "医院介绍", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalIntro hospitalIntro) {
        return toAjax(hospitalIntroService.insertHospitalIntro(hospitalIntro));
    }

    /**
     * 修改医院介绍
     */
    @RequiresPermissions("system:intor:edit")
    @Log(title = "医院介绍", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalIntro hospitalIntro) {
        return toAjax(hospitalIntroService.updateHospitalIntro(hospitalIntro));
    }

    /**
     * 删除医院介绍
     */
    @RequiresPermissions("system:intor:remove")
    @Log(title = "医院介绍", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(hospitalIntroService.deleteHospitalIntroByIds(ids));
    }

    // 医院名称回显
    @RequestMapping("system:intor:hospitalName")
    public AjaxResult hospitalName() {
        List<Hospital> list = hospitalIntroService.selectHospitalList();
        return AjaxResult.success(list);
    }
}
